#include <bits/stdc++.h>
using i64 = long long;
using u64 = unsigned long long;
using u32 = unsigned;
using u128 = unsigned __int128;
using i128 = __int128;
using namespace std;

void solve(vector<int>& a, vector<int>& b, int k) {
    set<int> st1, st2;
    for (int i = 0; i < a.size(); i++) {
        if (a[i] >= 0 && a[i] <= k) {
            st1.insert(a[i]);
        }
    }
    for (int i = 0; i < b.size(); i++) {
        if (b[i] >= 0 && b[i] <= k) {
            st2.insert(b[i]);
        }
    }

    if (st1.size() < k / 2 || st2.size() < k / 2) {
        cout << "NO" << endl;
        return ;
    }

    for (int i = 1; i <= k; i ++) {
        if (st1.find(i) == st1.end() && st2.find(i) == st2.end()) {
            cout << "NO" << endl;
            return ;
        }
    }

    cout << "YES" << endl;
}

// void test(){
//     vector<int> a{2};
//     vector<int> b{6, 4, 4, 2};
//     solve(a, b, 2);
// }

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int t;
    cin >> t;
    while (t--){
        // cin
        int m, n, k;
        cin >> n >> m >> k;
        vector<int> a(n);
        for (int i = 0; i < n; i++) cin >> a[i];
        vector<int> b(m);
        for (int i = 0; i < m; i++) cin >> b[i];
        solve(a, b, k);
    }

    // test();
    return 0;
}